package cn.microven.mindmap.components.node;

import javafx.scene.paint.Color;
import javafx.scene.shape.Rectangle;

/**
 * 矩形节点
 * 支持圆角
 *
 * @author 吴博维
 * @version 1.0
 */
public class RectangleNode extends AbstractMapNode<Rectangle> {
    @Override
    protected void initShape() {
        this.shape = new Rectangle();

        shape.arcHeightProperty().bindBidirectional(shape.arcWidthProperty());
        this.setBackgroundColor(new Color(255/255.0,187/255.0,0,1));
        shape.setStrokeWidth(2);
        this.setRadius(30);
        shape.setStroke(new Color(255/255.0,187/255.0,0,1));
        //绑定shape和text尺寸
        setShapeWidth(text.getWidth());
        setShapeHeight(text.getHeight());

    }

    @Override
    protected void setShapeWidth(double shapeWidth) {
        this.shape.setWidth(shapeWidth);
    }

    @Override
    protected double getShapeWidth() {
        return this.shape.getWidth();
    }

    @Override
    protected void setShapeHeight(double shapeHeight) {
        this.shape.setHeight(shapeHeight);
    }

    @Override
    protected double getShapeHeight() {
        return this.shape.getHeight();
    }

    @Override
    public double getRadius() {
        return shape.getArcHeight();
    }

    @Override
    public void setRadius(double radius) {
        shape.setArcHeight(radius);
    }

    public RectangleNode clone() {
        RectangleNode newNode = new RectangleNode();
        newNode.setBackgroundColor(new Color(this.getBackgroundColor().getRed(),this.getBackgroundColor().getGreen(),this.getBackgroundColor().getBlue(),this.getBackgroundColor().getOpacity()));
        newNode.setFontColor(new Color(this.getFontColor().getRed(),this.getFontColor().getGreen(),this.getFontColor().getBlue(),this.getFontColor().getOpacity()));
        newNode.setRadius(this.getRadius());
        newNode.setFontFamily(this.getFontFamily());
        newNode.setFontSize(this.getFontSize());

        Color borderColor = (Color)this.shape.getStroke();
        newNode.getNodeShape().setStroke(new Color(borderColor.getRed(),borderColor.getGreen(),borderColor.getBlue(),borderColor.getOpacity()));
        return newNode;
    }
}
